import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    //所有频道

    allChannel: [],

    // 我的频道数组

    myChannel: ["头条", "军事", "国际"],
  },

  mutations: {
    muChannels(state, val) {
      state.allChannel = val;
    },

    increment(state, index) {
      let channel = state.allChannel[index];

      state.myChannel.push(channel);

      state.allChannel.splice(index, 1);
    },

    decrement(state, index) {
      let channel = state.myChannel[index];

      state.allChannel.push(channel);

      state.myChannel.splice(index, 1);
    },
  },

  actions: {
    // 加载所有频道的方法

    muChannels(store, val) {
      store.commit("muChannels", val);
    },

    // 添加频道

    increment(store, index) {
      store.commit("increment", index);
    },

    // 删除频道

    decrement(store, index) {
      store.commit("decrement", index);
    },
  },
});
